#include <iostream>
#include <unordered_map>
using namespace std;

// 返回最小覆盖子串
string slidingWindow(string s, string t) {
    unordered_map<char, int> need, window;
    // 窗口左右边界
    int left = 0, right = 0;
    // 是否覆盖所有字符
    int valid = 0;
    // 子串起点和长度
    int start = 0;
    int len = INT_MAX;
    
    for (string::iterator iter = t.begin(); iter < t.end(); iter++)
        need[*iter]++;

    while (right < s.size()) {
        // 扩大窗口
        char c_right = s[right++];
        if (need.count(c_right)) {
            window[c_right]++;
            if (window[c_right] == need[c_right])
                valid++;
        }

        while (valid == need.size()) {
            // 更新子串信息
            if (right - left < len) {
                start = left;
                len = right - left;
            }
            // 缩小窗口
            char c_left = s[left++];
            if (need.count(c_left)) {
                if (window[c_left] == need[c_left])
                    valid--;
                window[c_left]--;
            }
        }
    }

    return len == INT_MAX ? "" : s.substr(start, len);
}